<template>
  <div class="content-wrap">
    <van-nav-bar :title="$route.query.type === 1 ? '设置昵称' : '设置个性签名'" left-text="取消" right-text="完成"
                 @click-left="$router.go(-1)" @click-right="sureEdit">
    </van-nav-bar>

    <van-cell-group :title="$route.query.type === 1 ? '新昵称' : '个性签名'">
      <van-field v-model="nickName" placeholder="输入新昵称" v-if="$route.query.type === 1"/>
      <van-field
        v-else
        v-model="autograph"
        type="textarea"
        placeholder="请输入个性签名"
        rows="4"
        autosize
        maxLength="100"
      />
    </van-cell-group>
  </div>
</template>

<script>
  import Socket from '../../utils/socket'

  export default {
    name: 'editUserMsg',
    data () {
      return {
        nickName: '',
        autograph: ''
      }
    },
    methods: {
      sureEdit () {
        let type = this.$route.query.type
        if (type === 1) {
          Socket.sendData('setUserNick', { nickname: this.nickName }).then(res => {
            this.$store.commit('setObjAttr', { obj: 'userData', attr: 'nickname', data: this.nickName })
            this.$router.go(-1)
          })
        } else {
          Socket.sendData('setUserContent', { content: this.autograph }).then(res => {
            this.$store.commit('setObjAttr', { obj: 'userData', attr: 'content', data: this.autograph })
            this.$router.go(-1)
          })
        }
      }
    },
    created () {
      this.nickName = this.$store.state.user.userData.nickname
      this.autograph = this.$store.state.user.userData.content
    }
  }
</script>

<style scoped>

</style>
